package aecs

import (
	"fmt"

	"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)

func (c *Client) CreateInstance(req *ecs.CreateInstanceRequest) (*ecs.CreateInstanceResponse, error) {
	client := c.Client
	// req := ecs.CreateCreateInstanceRequest()
	req.Method = "GET"
	req.Port = "8788"
	// req.InstanceType = "VGPU1R9001" //实例类型不为固定的值

	m := req.GetQueryParams()
	m["host_type"] = "GPU"                                 //todo 后续支持其他类型，如S1,S2.目前只需要GPU的
	req.VSwitchId = "2a1262dc-0483-4bd5-9b82-e5c7fffd4a8a" //todo 该值从控制台获取，后续通过网络接口进行设置

	// if err := mergo.Merge(request, req, mergo.WithOverride); err != nil {
	// 	return nil, fmt.Errorf("Error updating struct %w", err)
	// }
	response, err := client.CreateInstance(req)
	if err != nil {
		return nil, fmt.Errorf("Error creating instance %w", err)
	}

	return response, nil
}
